#!/bin/sh
APP_PATH=/opt/springboot-appsrm
APP_USER=springboot
APP_NAME=eagle-eye-web-api-boot-product-yinni
APP_FILE_EXT=jar
APP_ENV=product-yinni
JAVA_HOME=/opt/jdk1.8.0_112
JAVA_OPTS="-server -Xms1g -Xmx1g -Xmn512m -Djava.awt.headless=true -XX:MaxPermSize=256m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps "
cd ${APP_PATH}/
export JAVA_HOME
export JAVA_OPTS

CLASSPATH="./:/usr/local/jdk/lib:/usr/local/jdk/jre/lib"
export CLASSPATH

PATH=${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin:$PATH:$HOME/bin
export PATH
export LANG=zh_CN.UTF-8

ID=`ps uax | grep java | grep ${APP_NAME} | awk '{ print $2 }'`
echo "$ID"
kill -9 ${ID}
echo "SpringBoot process($ID) has been killed ...."
RUN_USER=`whoami`
if [[ ${RUN_USER} == root ]];then
    chown -R ${APP_USER}:${APP_USER} ${APP_PATH}
    su - ${APP_USER} -c "nohup java $JAVA_OPTS -jar $APP_PATH/$APP_NAME.$APP_FILE_EXT --spring.profiles.active=$APP_ENV> /dev/null 2>&1 &"
elif [[ ${RUN_USER} == ${APP_USER} ]];then
    nohup java ${JAVA_OPTS} -jar ${APP_PATH}/${APP_NAME}..${APP_FILE_EXT} --spring.profiles.active=${APP_ENV} > /dev/null 2>&1 &
fi
echo "SpringBoot is Starting ...."
sleep 3
echo "##########SpringBoot ${APP_NAME}##########"
ID=`ps uax | grep java | grep ${APP_NAME} | awk '{ print $2 }'`
echo "$ID"
echo "SpringBoot process $ID has started ...."
